package GUI.ElementTree;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import GUI.Components.RoundBorder;
import GUI.ElementTree.ElementTree;
import General.CurrentData;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
import javax.swing.tree.*;

/**
 *
 * @author David
 */
public class ElementTreeCellRenderer extends DefaultTreeCellRenderer
{

    private ImageIcon objectIcon;
    private ImageIcon nodeIcon;
    private ImageIcon lightIcon;
    private ImageIcon filterIcon;
    private ImageIcon sceneIcon;
    private ElementTree elementTree;

    public ElementTreeCellRenderer(ElementTree tree)
    {
        elementTree = tree;
        setForeground(UIManager.getColor("Button.background"));
        objectIcon = new ImageIcon("dat//img//menu//3dobj.png");
        nodeIcon = new ImageIcon("dat//img//menu//nodeIcon.png");
        lightIcon = new ImageIcon("dat//img//menu//light.png");
        filterIcon = new ImageIcon("dat//img//menu//filter.png");
        sceneIcon = new ImageIcon("dat//img//other//sceneIcon.png");
    }

    @Override
    public Component getTreeCellRendererComponent(JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus)
    {
        super.getTreeCellRendererComponent(tree, value, sel,
                expanded, leaf, row, hasFocus);
        DefaultMutableTreeNode tempNode = (DefaultMutableTreeNode) value;
        if (tempNode.equals(CurrentData.getEditorWindow().getTree().getSpatialsNode()))
        {
            setIcon(objectIcon);
        } else if (tempNode.equals(CurrentData.getEditorWindow().getTree().getLightsNode()))
        {
            setIcon(lightIcon);
        } else if (tempNode.equals(CurrentData.getEditorWindow().getTree().getFiltersNode()))
        {
            setIcon(filterIcon);
        } else if (tempNode.equals(CurrentData.getEditorWindow().getTree().getOthersNode()))
        {
            setIcon(null);
        } else if (tempNode.equals(CurrentData.getEditorWindow().getTree().getRootNode()))
        {
            setIcon(sceneIcon);
        } else if (tempNode.getAllowsChildren())
        {
            setIcon(nodeIcon);
        } else
        {
            check(tempNode);
        }
        return this;
    }

    private void check(TreeNode tempNode)
    {
        if (tempNode.getParent() != null)
        {
            if (tempNode.getParent().equals(elementTree.getSpatialsNode()))
            {
                setIcon(objectIcon);
            } else if (tempNode.getParent().equals(elementTree.getLightsNode()))
            {
                setIcon(lightIcon);
            } else if (tempNode.getParent().equals(elementTree.getFiltersNode()))
            {
                setIcon(filterIcon);
            } else
            {
                check(tempNode.getParent());
            }
        }
    }
}